<?php

use Workerman\Worker;
use Workerman\Timer;

require_once __DIR__ . '/vendor/autoload.php';

$worker = new Worker();
$worker->count = 3;

//设置打印的文件属性
Worker::$stdoutFile = __DIR__.'/logs/stdout.log';

function send_mail($task)
{
    echo "send mail\n";
}

$worker->onWorkerStart = function(Worker $task)
{
    //只在0进程上设置定时器，其他1,2，3号进程不设置定时器
    if($task->id == 0){
        //每 2.5s 执行一次
        $timer_interval = 2.5;
//        Timer::add($timer_interval, function()
//        {
//            echo "timer run\n";
//        });

        //定时器
        //false 执行一次 true 循环执行
        Timer::add($timer_interval, 'send_mail',array($task),true);
    }

};

Worker::runAll();